//
//  graftingHospitolViewController.m
//  yilutongxing
//
//  Created by  Mac on 2017/5/8.
//  Copyright © 2017年 YZE. All rights reserved.
//

#import "graftingHospitolViewController.h"
#import "graftingHospitolCell.h"
#import "PYSearch.h"
#import "MyHospitolViewController.h"
@interface graftingHospitolViewController ()<PYSearchViewControllerDelegate,PYSearchViewControllerDataSource,UITableViewDelegate,UITableViewDataSource>
@property (nonatomic,assign )BOOL type;

@property (nonatomic ,assign)BOOL tag;
@property (nonatomic)UIViewController *vc;
@property(nonatomic,strong)NSArray* dataArr;
@end

@implementation graftingHospitolViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self searchView];
}
- (void)didClickCancel:(PYSearchViewController *)searchViewController{
    [self dismissViewControllerAnimated:NO completion:^{
        [self dismissViewControllerAnimated:YES completion:nil];
    }];
}
-(void)searchView{
    self.tag = false;
    UITableView *tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, -SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT - 44) style:UITableViewStyleGrouped];
    //创建控制器
    PYSearchViewController *searchViewController = [PYSearchViewController searchViewControllerWithHotSearches:nil searchBarPlaceholder:NSLocalizedString(@"搜索医院",@"搜索类型") didSearchBlock:^(PYSearchViewController *searchViewController, UISearchBar *searchBar, NSString *searchText) {
        
        [UIView animateWithDuration:.1 animations:^{
            tableView.frame = CGRectMake(0, 44, SCREEN_WIDTH, SCREEN_HEIGHT-44);
        } completion:nil];
        self.tag = true;
    }];
    // 4. 设置代理
    searchViewController.delegate = self;
    searchViewController.showSearchHistory = NO;
    //     searchViewController.searchHistoryStyle =PYSearchHistoryStyleCell; // 搜索历史风格根据选择
    searchViewController.cancelButton.tintColor = [UIColor colorWithRed:102/255.0 green:102/255.0 blue:102/255.0 alpha:1];
    searchViewController.cancelButton.title = @"取消";

    self.vc = searchViewController;
    tableView.delegate = self;
    tableView.dataSource = self;
    [searchViewController.view addSubview:tableView];
    [tableView registerNib:[UINib nibWithNibName:@"graftingHospitolCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"cell"];
    
    
    // 5. 跳转到搜索控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:searchViewController];
    
    [self presentViewController:nav animated:YES completion:nil];

}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - PYSearchViewControllerDelegate
- (void)searchViewController:(PYSearchViewController *)searchViewController searchTextDidChange:(UISearchBar *)seachBar searchText:(NSString *)searchText{
    if (self.tag&&searchText.length) {
        // Simulate a send request to get a search suggestions
        //        dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.25 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        //            NSMutableArray *searchSuggestionsM = [NSMutableArray array];
        //            for (int i = 0; i < arc4random_uniform(5) + 10; i++) {
        //                NSString *searchSuggestion = [NSString stringWithFormat:@"Search suggestion %d", i];
        //                [searchSuggestionsM addObject:searchSuggestion];
        //            }
        //            // Refresh and display the search suggustions
        //            searchViewController.searchSuggestions = searchSuggestionsM;
        //        });
    }
}
-(NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return 1;
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return 5;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
        graftingHospitolCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cell" forIndexPath:indexPath];
    cell.selectionStyle=UITableViewCellSelectionStyleNone;
    
        return cell;
    
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 102;
}

-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 0.1;
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    MyHospitolViewController *vc=[MyHospitolViewController new];
    UINavigationController *navi=[[UINavigationController alloc]initWithRootViewController:vc];
  [self.vc presentViewController:navi animated:YES completion:nil];
}

@end
